#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main()
{
  int fd;
  fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY | O_NONBLOCK);

  if(fd == 1)
     printf("\n  Error! in Opening ttyUSB0\n");
  else
     printf("\n  ttyUSB0 Opened Successfully\n");


  struct termios PortSet;

  tcgetattr(fd, &PortSet);

  cfsetispeed(&PortSet,B115200);
  cfsetospeed(&PortSet,B115200);

  PortSet.c_cflag |= CREAD | CLOCAL;
  PortSet.c_cflag &= ~PARENB;  //DISABLES THE PARITY
  PortSet.c_cflag &= ~CSTOPB;  //1 BIT
  PortSet.c_cflag &= ~CSIZE;  //CLEAR SIZE
  PortSet.c_cflag |=  CS8;  //8 BIT DATAS
  PortSet.c_iflag &= ~(IXON | IXOFF | IXANY);
  PortSet.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);

  PortSet.c_oflag &= -OPOST;

  PortSet.c_cflag &= ~CRTSCTS;

  PortSet.c_cc[VMIN] = 10;
  PortSet.c_cc[VTIME] = 0;

  if((tcsetattr(fd,TCSANOW,&PortSet)) != 0) 
    { 
      perror("\n  com set error"); 
      return -1; 
    } 
  else
    printf("set done!\n"); 

  char read_buffer[32]; 
  int  bytes_read=0;
  int i = 0;

while(1)
{
  bytes_read = read(fd,&read_buffer,32);
  for(i=0;i<bytes_read;i++)
      printf("\n %c", read_buffer[i]);
}
  close(fd);
  return 0;
}
